package com.rrd.dw.mr.gzip.kafka;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.third.phonehelp.PhoneHelpUMReord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/**
 * 电话邦联通建模
 *
 * @author xj
 */
public class PhoneHelpUMParse extends ParseBase {
    private Text val = new Text();
    private Text key = new Text();

    /**
     * 电话邦联通建模
     *
     * @param model
     * @throws InterruptedException
     * @throws IOException
     */
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {

        PhoneHelpUMReord obj = (PhoneHelpUMReord) model;
        String dataStr = obj.getData();
        JSONObject info = JSON.parseObject(dataStr);
        JSONObject data = info.getJSONObject("data");
        StringBuilder sb = getBaseInfo(obj, successful);
        //接口描述
        sb.append(info.getString("msg")).append(CRT001);
        //接口状态码
        sb.append(info.getString("status")).append(CRT001);
        //本次输出结果对应的有效日期
        sb.append(data.getString("result_date")).append(CRT001);
        // 好分期定制评分
        sb.append(data.getString("bxf_scoreA13")).append(CRT001);
        // 人人贷定制评分
        sb.append(data.getString("bxf_scoreA11")).append(CRT001);
        // 本次成功请求的唯一标识
        sb.append(data.getString("sid")).append(CRT001);

        StringBuilder txSb = getBaseInfo(obj);
        key.set(getKey());
        val.set((sb.toString() + txSb.toString()).replace("\n", " ").replace("\r", " "));
        context.write(key, val);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_phonehelp_unicom_inc";
    }

    @Override
    public String getType() {
        return RecordType.PHONE_HELP_UM_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "电话邦联通建模";
    }


}
